package mars.activity;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import bear.download.Circleread;
import bear.download.HttpsUtils;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class bookActivity extends ListActivity{
	private Button turnup0,turndown0;
	private TextView pages0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.book);
		turnup0=(Button)findViewById(R.id.turnup0);
		turndown0=(Button)findViewById(R.id.turndown0);
		pages0=(TextView)findViewById(R.id.pages0);
		pages0.setText("/");
		HttpsUtils jin=new HttpsUtils();
		String circleUrl=jin.get("https://www.loushiapp.com/?c=say&a=getsay&hash="+landActivity.hash);
		try{
			SAXParserFactory cu = SAXParserFactory.newInstance();
			XMLReader reader=cu.newSAXParser().getXMLReader();
			reader.setContentHandler(new Circleread());
			reader.parse(new InputSource(new StringReader(circleUrl)));
		}catch(Exception e){
			e.printStackTrace();
		}			   
		String sendnames[] = Circleread.sendname1.split("\\$");
		String createtimes[]=Circleread.createtime1.split("\\$");
		String pagecontents[]=Circleread.pagecontent1.split("\\$");
		
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for(int i=0;i<Circleread.n;i++){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("text7", sendnames[i]);
		map.put("time", createtimes[i]);
		map.put("mycontent", pagecontents[i]);
		list.add(map);
		}
		SimpleAdapter listAdapter = new SimpleAdapter(bookActivity.this, list,
				R.layout.bookapp, new String[] { "text7", "time","mycontent"},
				new int[] { R.id.text7,R.id.time,R.id.mycontent});
		setListAdapter(listAdapter);
		
		pages0.setText("/");
		
		turnup0.setOnClickListener(new Button.OnClickListener()
	    {
			public void onClick(View v) {
				// TODO Auto-generated method stub;
			}	
	    });
		turndown0.setOnClickListener(new Button.OnClickListener()
	    {
			public void onClick(View v) {
				// TODO Auto-generated method stub;
			}	
	    });
	}
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		//System.out.println("id----------------" + id);
		//System.out.println("position----------" + position);
	}
}
